package com.polling;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
public class Demo extends HttpServlet{
 
	private static final long serialVersionUID = 1L;
	private long count = 0;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
		Map<String, String[]> maps = request.getParameterMap();
		Map<Object,Object> map = new HashMap<Object,Object>();
		Map<Object,Object> data = new HashMap<Object,Object>();  
		System.out.println("count = " + count++);
		if(maps != null && maps.containsKey("future")) {
			System.out.println("param = " + maps.get("future"));
		} else {
			map.put("type", "event");
			map.put("name", "message");
			data.put("future", "a05324f5-9e88-4b79-afb3-0033ad91a939" );
			map.put("data", data);
		}
		JSONObject jsonObject = JSONObject.fromObject(map);  
		System.out.println(jsonObject);  
		out.print(jsonObject);
		out.flush();
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		doGet(request, response);
	}
}